package cn.ffcs.uec.organization.vo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import lombok.Getter;
import lombok.Setter;
import cn.ffcs.uec.organization.dao.UecOrgDeptDao;
import cn.ffcs.uec.staff.model.UecStaffInfo;
import cn.ffcs.uom.common.constants.BaseUnitConstants;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.StrUtil;

@Getter
@Setter
public class UecOrgDeptVo implements Serializable {
	private static final long serialVersionUID = 905576372508896018L;

	private String org;

	private String code;

	private String porg;

	private String orgname;

	private String orgtype;

	private String shortname;

	// 分管领导
	private String glbdef1;

	// 负责人
	private String principal;
	
	/**
	 * 分管领导姓名
	 * @return
	 */
	public String getGlbdef1Name() {
		if (!StrUtil.isNullOrEmpty(this.glbdef1)) {
			String sql = "SELECT * FROM UEC_STAFF_INFO A WHERE A.STATUS_CD=? AND A.PK_PSNDOC=?";
			List<Object> params = new ArrayList<Object>();
			params.add(BaseUnitConstants.ENTT_STATE_ACTIVE);
			params.add(this.glbdef1);

			UecStaffInfo uecStaffInfo = repository().jdbcFindObject(sql,
					params, UecStaffInfo.class);
			if(uecStaffInfo != null) {
				return uecStaffInfo.getName();
			}
		}
		
		return "";
	}
	
	/**
	 * 负责人姓名
	 * @return
	 */
	public String getPrincipalName() {
		if (!StrUtil.isNullOrEmpty(this.principal)) {
			String sql = "SELECT * FROM UEC_STAFF_INFO A WHERE A.STATUS_CD=? AND A.PK_PSNDOC=?";
			List<Object> params = new ArrayList<Object>();
			params.add(BaseUnitConstants.ENTT_STATE_ACTIVE);
			params.add(this.principal);

			UecStaffInfo uecStaffInfo = repository().jdbcFindObject(sql,
					params, UecStaffInfo.class);
			if(uecStaffInfo != null) {
				return uecStaffInfo.getName();
			}
		}
		
		return "";
	}

	/**
	 * 获取dao
	 * 
	 * @return
	 */
	public static UecOrgDeptDao repository() {
		return (UecOrgDeptDao) ApplicationContextUtil.getBean("uecOrgDeptDao");
	}
}
